<?php
// +----------------------------------------------------------------------
// | B5Yii2CMF V3.0 [快捷通用基础管理开发平台]
// +----------------------------------------------------------------------
// | Author=>冰舞 <357145480@qq.com>
// +----------------------------------------------------------------------
declare (strict_types=1);

namespace api\modules\admin\controllers\system;

use api\modules\admin\AuthController;
use api\utils\libs\CommonAction;
use common\models\system\Position;
use common\services\system\PositionService;

class PostController extends AuthController
{
    use CommonAction;

    protected string $model = Position::class;
    protected bool $validate = true;


    // 获取当前登录用户的岗位列表
    public function actionGetSelect(): array
    {
        return $this->success('', ['list' => PositionService::selectUserPositionSelectList($this->user_id)]);
    }


    protected function saveBefore(Position $model, string $type): string
    {
        if ($type == 'edit' && !PositionService::checkHasPositionPerm($this->user_id, $model->id)) {
            return '无权限此操作';
        }
        return '';
    }

    /**
     * 查询添加管理员时
     * @return array
     */
    public function actionAjaxFormList(): array
    {
        return $this->success('', ['list' => PositionService::getList()]);
    }

    protected function exportBefore(array $list): array
    {
        $row = [
            'id' => '编号',
            'pos_key' => '编码',
            'name' => '岗位名称',
            'remark' => '备注',
        ];
        $bold = ['A1:D1' => true];
        $width = ['a' => 10, 'b' => 20, 'c' => 20, 'd' => 40];
        $size = ['a1:A6' => 18];
        $wrap = ['d' => true];
        $background = ['b' => 'FF0000'];
        $color = ['a1' => 'FF0000'];
        return ['list' => $list, 'row' => $row, 'fileName' => '岗位列表', 'bold' => $bold, 'width' => $width, 'size' => $size, 'wrap' => $wrap, 'background' => $background, 'color' => $color];
    }
}
